package com.rm.system.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.jfinal.ext.plugin.sqlinxml.SqlKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Model;

public class Role extends Model<Role> {
	public static final Role dao = new Role();

	public Collection<String> getResUrl(String role) {
		Collection<String> urls = new ArrayList<String>();
		// urls.add("/test");
		Role r = getRoleByName(role);
		if (r == null)
			return urls;
		long roleid = r.getBigDecimal("roleid").longValue();
		List<Res> rs = Res.dao.find(SqlKit.sql("system.role.getRoleRes"),
				roleid);
		for (Res res : rs) {
			if(StrKit.isBlank(res.getStr("menu_url")))
				continue;
			urls.add(res.getStr("menu_url"));
		}
		return urls;
	}

	private Role getRoleByName(String role) {
		Role r = Role.dao.findFirst(SqlKit.sql("system.role.findbyname"), role);
		return r;
	}
}
